package net.dreamlu.controller.api;

import java.io.BufferedOutputStream;
import java.io.IOException;

import net.dreamlu.config.Consts;
import net.dreamlu.kit.ImageKit;

import com.jfinal.core.Controller;
import com.jfinal.kit.StringKit;

/**
 * 二维码
 * @author L.cm
 * @date Oct 26, 2013 10:34:10 AM
 */
public class QRcode extends Controller {
	
	public void index() throws IOException {
		String text = getRequest().getQueryString();
		if (StringKit.isBlank(text)) {
			text = Consts.DOMAIN_URL;
		}
		byte[] bs = ImageKit.qRcode(text, 90);
		BufferedOutputStream bos = new BufferedOutputStream(getResponse().getOutputStream());
	    bos.write(bs, 0, bs.length);
	    if (bos != null) {
	    	bos.close();
	    }
    	bos.flush();
    	renderNull();
	}
}
